<template>
    <div class="overlay" v-if="modelValue">
        <LandscapeSignature @getPngUrl="handlePngUrl" @back="handleBack" />
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import LandscapeSignature from './LandscapeSignature.vue';

export default defineComponent({
    name: 'OverlayModal',
    components: {
        LandscapeSignature
    },
    props: {
        modelValue: {
            type: Boolean,
            required: false,
        },
    },

    emits: ['update:modelValue', 'confirm'], // 支持 v-model 和 confirm 事件

    setup(props, { emit }) {
        console.log(props)

        const handlePngUrl = (pngUrl: any) => {
            console.log('接收到子组件的 pngUrl:', pngUrl);
            emit('confirm', pngUrl); // 将 pngUrl 传递给父组件
            // isVisible.value = false;
            emit('update:modelValue', false)
        }

        const handleBack = () => {
            emit('update:modelValue', false)
        }

        return { handlePngUrl, handleBack };
    },
});
</script>

<style scoped>
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 800px;
    overflow: auto;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: red;
    color: white;
    border: none;
    padding: 5px 10px;
    cursor: pointer;
}
</style>